package cn.jtfadmin.base.dict;

import cn.jtfadmin.base.dict.config.dictEntityAutoConfig.DictEntityAutoConfiguration;
import cn.jtfadmin.base.dict.service.impl.EnumDictScanConfig;
import cn.jtfadmin.base.lang.config.module.DefaultModuleInfoDTO;
import cn.jtfadmin.base.lang.config.module.ModuleInfo;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;

@Configuration
@ComponentScan(basePackages = "cn.jtfadmin.base.dict")
@Import(value = DictEntityAutoConfiguration.class)
public class BaseDictAutoConfiguration {

    /**
     * 环境中获取字典扫描包key
     */
    public static final String ENUM_DICT_SCAN_BASE_PACKAGE_KEY = "app.config.dict.enumScanBasePackage";

    /**
     * 环境中获取字典扫描包,缺省值
     */
    public static final String ENUM_DICT_SCAN_BASE_PACKAGE_DEFAULT_VALUE = "cn/jtfadmin";



    @Bean
    public ModuleInfo baseDictModuleInfo(){
        return new DefaultModuleInfoDTO("baseDict", "字典模块", "字典模块", getClass().getPackage().getName());
    }

    @Bean
    @ConditionalOnMissingBean(value = EnumDictScanConfig.class)
    EnumDictScanConfig enumDictScanConfig(Environment environment) {
        String basePackage = environment.getProperty(ENUM_DICT_SCAN_BASE_PACKAGE_KEY, ENUM_DICT_SCAN_BASE_PACKAGE_DEFAULT_VALUE);
        return new EnumDictScanConfig(basePackage);
    }
}
